<template>
	<view class="container">
		<!-- 自定义导航栏 -->
		<view class="nav-bar">
			<view class="status-bar" :style="{height: statusBarHeight + 'px'}"></view>
			<view class="nav-content">
				<view class="nav-left" @click="goBack">
					<u-icon name="arrow-left" color="#333" size="18"></u-icon>
				</view>
				<view class="nav-title">问题详情</view>
				<view class="nav-right"></view>
			</view>
		</view>
		
		<!-- 主内容区域 -->
		<view class="main-content">
			<!-- 问题详情 -->
			<view class="question-detail">
				<view class="question-title">{{title}}</view>
				<view class="question-content">{{content}}</view>
			</view>
			
			<!-- 相关问题 -->
			<view class="related-questions">
				<view class="related-title">相关问题</view>
				<view class="related-list">
					<view class="related-item" v-for="(item, index) in relatedQuestions" :key="index" @click="goToOtherDetail(item)">
						<text class="related-text">{{item.title}}</text>
						<u-icon name="arrow-right" color="#C8C8C8" size="16"></u-icon>
					</view>
				</view>
			</view>
			
			<!-- 联系客服 -->
			<view class="contact-service">
				<view class="contact-title">还有疑问？</view>
				<button class="contact-btn" @click="contactService">联系客服</button>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			statusBarHeight: 20,
			id: null,
			title: '',
			content: '',
			relatedQuestions: [
				{
					id: 1,
					title: '租地怎么续租租金'
				},
				{
					id: 2,
					title: '如何查看我的农作物生长状态'
				},
				{
					id: 3,
					title: '如何领取收获的农产品'
				}
			]
		}
	},
	onLoad(options) {
		// 获取状态栏高度
		this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
		
		// 获取传递的参数
		if (options.id) {
			this.id = options.id;
		}
		if (options.title) {
			this.title = decodeURIComponent(options.title);
		}
		if (options.content) {
			this.content = decodeURIComponent(options.content);
		}
		
		// 过滤掉当前问题，只显示其他相关问题
		this.relatedQuestions = this.relatedQuestions.filter(item => item.id != this.id);
	},
	methods: {
		// 返回上一页
		goBack() {
			uni.navigateBack();
		},
		// 跳转到其他问题详情
		goToOtherDetail(item) {
			// 获取完整问题内容
			const fullQuestion = this.getFullQuestionById(item.id);
			
			uni.navigateTo({
				url: `/pages/my/questionDetail?id=${fullQuestion.id}&title=${encodeURIComponent(fullQuestion.title)}&content=${encodeURIComponent(fullQuestion.content)}`
			});
		},
		// 根据ID获取完整问题信息
		getFullQuestionById(id) {
			// 这里应该从服务器获取，这里模拟一些数据
			const questionMap = {
				1: {
					id: 1,
					title: '租地怎么续租租金',
					content: '您可以在个人中心-我的租地中查看您的租地信息，点击需要续租的地块，进入详情页面后点击"续租"按钮，按照提示完成支付即可续租成功。'
				},
				2: {
					id: 2,
					title: '如何查看我的农作物生长状态',
					content: '您可以在首页-农场监控中查看您的农作物实时生长状态，也可以在个人中心-我的农场中查看详细信息。'
				},
				3: {
					id: 3,
					title: '如何领取收获的农产品',
					content: '当您的农作物成熟后，系统会自动通知您。您可以选择自提或配送到家，在个人中心-我的收获中进行相应操作。'
				}
			};
			
			return questionMap[id] || {
				id: 0,
				title: '未知问题',
				content: '该问题不存在或已被删除。'
			};
		},
		// 联系客服
		contactService() {
			uni.navigateTo({
				url: '/pages/Intelligent/AiView'
			});
		}
	}
}
</script>

<style scoped>
.container {
	background-color: #f5f5f5;
	min-height: 100vh;
}

/* 自定义导航栏 */
.nav-bar {
	background-color: #ffffff;
	border-bottom: 1rpx solid #f0f0f0;
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: 1000;
}

.status-bar {
	width: 100%;
	background-color: #ffffff;
}

.nav-content {
	display: flex;
	align-items: center;
	justify-content: space-between;
	height: 88rpx;
	padding: 0 30rpx;
	background-color: #ffffff;
}

.nav-left {
	width: 60rpx;
	height: 60rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}

.nav-title {
	font-size: 32rpx;
	font-weight: bold;
	color: #333;
	text-align: center;
	flex: 1;
}

.nav-right {
	width: 60rpx;
	flex-shrink: 0;
}

/* 主内容区域 */
.main-content {
	padding-top: calc(88rpx + var(--status-bar-height));
	padding-bottom: 40rpx;
}

/* 问题详情 */
.question-detail {
	background-color: #ffffff;
	margin-top: 20rpx;
	padding: 30rpx;
}

.question-title {
	font-size: 32rpx;
	font-weight: bold;
	color: #333;
	margin-bottom: 20rpx;
}

.question-content {
	font-size: 28rpx;
	color: #666;
	line-height: 1.6;
}

/* 相关问题 */
.related-questions {
	background-color: #ffffff;
	margin-top: 20rpx;
	padding: 30rpx;
}

.related-title {
	font-size: 30rpx;
	font-weight: bold;
	color: #333;
	margin-bottom: 20rpx;
}

.related-item {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 20rpx 0;
	border-bottom: 1px solid #f5f5f5;
}

.related-item:last-child {
	border-bottom: none;
}

.related-text {
	font-size: 28rpx;
	color: #666;
}

/* 联系客服 */
.contact-service {
	background-color: #ffffff;
	margin-top: 20rpx;
	padding: 30rpx;
	display: flex;
	flex-direction: column;
	align-items: center;
}

.contact-title {
	font-size: 28rpx;
	color: #666;
	margin-bottom: 20rpx;
}

.contact-btn {
	width: 60%;
	height: 80rpx;
	background-color: #4CAF50;
	color: #ffffff;
	font-size: 28rpx;
	border-radius: 40rpx;
	display: flex;
	align-items: center;
	justify-content: center;
}
</style> 